package cn.com.sinosoft.ares.insurance.service;

import cn.com.sinosoft.ares.insurance.dao.AresClientConfigDao;
import cn.com.sinosoft.ares.insurance.dao.PrpDProjectDao;
import cn.com.sinosoft.ares.insurance.dao.TemproomDao;
import cn.com.sinosoft.ares.insurance.model.PrpDUserDual;
import cn.com.sinosoft.ares.insurance.model.Temproom;
import cn.com.sinosoft.ares.insurance.service.exception.ProductNotExistException;
import cn.com.sinosoft.ares.insurance.service.exception.RepetitionException;
import cn.com.sinosoft.ares.insurance.service.struct.Account;
import cn.com.sinosoft.ares.insurance.struct.Request;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

/**
 * Description: 房惠险抽象方法
 * Author: lishangmin
 * Created: 2018-09-05 10:38
 */
public abstract class AbstractRoomInsureService extends AbstractInsureService<String, Request> {

    //承保方法
    @Override
    public String insure(Request request) {
        return null;
    }

    @Autowired
    AresClientConfigDao aresClientConfigDao;

    /**
     * 获取账户信息
     * @param userName 用户名
     * @return 账户信息
     */
    protected Account getAccount(String userName){
        //机构代码
        String comCode = this.getComCode(userName);
        //新的机构代码
        String newComeCode = this.getNewComCode(comCode);
        Account account = Account.builder().accountId(userName).comCode(comCode)
                .newComCode(newComeCode).remoteAddress("000.000.000.000").build();
        return account;
    }

    /**
     * 校验账户是否存在产品信息
     * @param userName 用户名
     * @param productCode 第三方，传送过来的 产品代码
     */
    protected void checkRisk(String userName,String productCode){
        PrpDUserDual prpDUserDual = prpDUserDao.selectByRiskcodeAndUsercode(productCode, userName);
        if(prpDUserDual == null) throw new ProductNotExistException();
    }

    @Autowired
    PrpDProjectDao prpDProjectDao;

    /**
     * 查询定量保费
     * @param rationType 定量类型
     * @param riskCode   险种代码
     * @return 定量保费
     */
    protected BigDecimal calculate(String rationType, String riskCode){
        BigDecimal premium = prpDProjectDao.selectPremium(rationType,riskCode);
        return premium;
    }

    @Autowired
    TemproomDao temproomDao;

    /**
     * 校验是否重复投保
     */
    protected void checkRepetition(String agentCode,String orderId){
        Temproom temproom = temproomDao.selectByagentcode(agentCode,orderId);
        if(temproom != null) throw new RepetitionException();
    }


}
